<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<%@ taglib prefix="f" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path=request.getContextPath();
%>    

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

	<link href="/resources/css/bootstrap-4.3.1/css/bootstrap.css" rel="stylesheet">
	<script type="text/javascript" src="/resources/js/jquery-3.2.1/jquery.js"></script>
	<script type="text/javascript" src="/resources/js/jqueryvalidate/jquery.validate.js"></script>
	<script type="text/javascript" src="/resources/js/jqueryvalidate/localization/messages_zh.js"></script>
	<script type="text/javascript" src="/resources/css/bootstrap-4.3.1/js/bootstrap.js"></script>
	
</head>
<body>
	<c:forEach items="${topicPage.list }" var = "topic">
		<h3>${topic.name } </h3>
		
		
		<table class = "table">
			<tr>
				<td>选项</td>
				<td>小计</td>
				<td>比例</td>
				<td>更新投票</td>
			</tr>
			<c:forEach items="${topic.list }" var="item">
			<tr>
				<td>${item.name }
					
				</td>
				<td class = "count">${item.votes }</td>
				<td class = "progressIng">
					${item.progress }
				</td>
				<td>
					<a href="toUpdateVote?id=${topic.id }&tid=${item.id}"><button type="button" class="btn btn-warning" >更新投票</button></a>
				</td>
			</tr>
			</c:forEach> 
			
			<tr>
				<td>本题有效填写人数</td>
				<td class = "total">${topic.total }</td>
				<td></td>
			</tr>
		</table>
		
		
	</c:forEach>


	<nav aria-label="Page navigation example">
		  <ul class="pagination">
		    <li class="page-item"><a class="page-link" href="showAll?pageNum=1">首页</a></li>
		    <c:forEach begin="${topicPage.pageNum-2>1?topicPage.pageNum-2:1}" 
		       end="${topicPage.pageNum+2<topicPage.pages ? topicPage.pageNum+2:topicPage.pages}" step="1" var="page">
		    	<c:if test="${page==topicPage.pageNum}">
		    		<li class="page-item active" aria-current="page">
				      <a class="page-link">
				         ${page}
				        <span class="sr-only">(current)</span>
				      </a>
				    </li>
		    	</c:if>
		    	<c:if test="${page!=topicPage.pageNum}">
    		<li class="page-item"><a class="page-link" href="showAll?pageNum=${page }" >${page}</a></li>
    		</c:if>
    	
    		</c:forEach>
		    <li class="page-item"><a class="page-link" href="showAll?pageNum=${topicPage.pages }">尾页</a></li>
		  </ul>
		</nav>
		
	<script type="text/javascript">
		var num = 0;
		
		/* $(".count").each(function(){
			
			num += parseInt($(this).html());
				
		}) */
		
		/* $(".total").append("<p>"+num+"<p>") */
		
		/* $(".count").each(function(){
			
			$.post("showPercent",{currentNum:parseInt($(this).html()),totalNum:num},function(msg){
				
				$(".progressIng").append(msg);
				
			})	
		}) */
		 
	
	</script>

</body>
</html>